package lab03.test14;

import java.sql.*;

public class Test14 {
    public static void main(String[] args) {
        Connection connection=null;
        PreparedStatement statement=null;
        ResultSet resultSet=null;

        String sql="select * from t_userinfo";

        String str="insert into t_userinfo(usercode,username,password,email) " +
                "values('7107,'何至','123456','251807680@qq.com')";

        try {
            Class.forName("com.mysql.jdbc.Driver");

            connection= DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/java_2017?characterEncoding=utf-8&useSSL=false&serverTimezone=GMT",
                    "root",
                    "251807680wmh"
            );

            //statement=connection.prepareStatement(str);
            try {
                statement=connection.prepareStatement(sql);
            } catch (SQLException e) {
                e.printStackTrace();
            }

            //statement.execute(str);

            resultSet=statement.executeQuery();

            while (resultSet.next()){
                System.out.println(resultSet.getString(1)+"\t"+resultSet.getString(2)
                        +"\t"+resultSet.getString(3)+"\t"+resultSet.getString(4));
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                connection.close();
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }


    }
}

